<template xmlns:th="http://www.w3.org/1999/xhtml">
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="项目名称" prop="status">
        <el-select
          v-model="queryParams.checkName"
          placeholder="项目名称"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in checkList"
            :key="dict.rcname"
            :label="dict.rcname"
            :value="dict.rcname"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="检查单号" prop="checkId">
        <el-input
          v-model="queryParams.checkId"
          placeholder="请输入检查单号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <template>
      <el-tabs v-model="activeName"  stretch="true">
        <el-tab-pane label="用户管理" name="first">
          <el-table
          :data="checkList"
          row-key="rricd"
          default-expand-all
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          width="100%"
          border
        >
          <el-table-column key="rcid" prop="rcid" label="项目ID" ></el-table-column>
          <el-table-column key="rrname" prop="rrname" label="项目名称" ></el-table-column>
          <el-table-column key="rcprice" prop="rcprice" label="项目价格" ></el-table-column>
          <el-table-column key="rcname" prop="rcname" label="患者姓名" ></el-table-column>
          <el-table-column key="rrcstatus" prop="rrcstatus" label="检查状态" :formatter="statusFormat"></el-table-column>
          <el-table-column key="createtime" prop="createtime" label="创建时间" ></el-table-column>
          <el-table-column key="createby" prop="createby" label="创建人" ></el-table-column>
        </el-table>
        </el-tab-pane>
        <el-tab-pane label="配置管理" name="second">
          <el-table
            :data="checkList"
            row-key="rricd"
            default-expand-all
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
            width="100%"
            border
          >
            <el-table-column key="rcid" prop="rcid" label="项目ID" ></el-table-column>
            <el-table-column key="rrname" prop="rrname" label="项目名称" ></el-table-column>
            <el-table-column key="rcamount" prop="rcamount" label="总金额" ></el-table-column>
            <el-table-column key="count" prop="count" label="检查次数"></el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
    </template>
  </div>
</template>

<script>
import { listCheckId,findById } from "@/api/check/edit";
import Treeselect from "@riophae/vue-treeselect";
import { getToken } from "@/utils/auth";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Dept",
  components: { Treeselect },
  data() {
    return {
      value1: '',
      activeName: 'second',
      checkName :[],
      radio1: this.grouped,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 检查单数据
      resultCheckList: [],
      // 检查单数据
      checkList: [],
      dateRange: [],
      // 部门树选项
      deptOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        checkId:"",
        checkName: undefined,
        status: 2
      },
        // 上传检查结果
        upload: {
            // 设置上传的请求头部
            headers: { Authorization: "Bearer " + getToken() },
            // 上传的地址
            url: process.env.VUE_APP_BASE_API + "/check/upload"
        },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
    this.getDicts("check_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
      handleClick(tab, event) {
          console.log(tab, event);
      },
      uploaded(response){
          this.form.rrcpicture = response.msg;
          console.log(this.form.rrcpicture);
      },
    /** 查询表单列表 */
    getList() {
        this.loading = true;
        findById(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
            this.checkList = response.data;
            //this.checkList = this.handleTree(response.data);
            this.loading = false;
      });
    },

    getIDList(){
        this.loading = true;
        listCheckId(this.queryParams.checkId).then(response => {
            this.checkList = this.handleTree(response.data);
            this.loading = false;
        });
    },


    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.deptId,
        label: node.deptName,
        children: node.children
      };
    },
    // 字典状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.rrcstatus);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
          rrcid: 0,
          rcname: undefined,
          rrname: undefined,
          rrcstatus: 1,
          rrcresult: '王中王',
          rrcpicture:undefined,
          rcremark:undefined,
          createby: undefined,
          createtime: undefined,
          updateby: undefined,
          updatetime: undefined,
          remark:undefined,

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getIDList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
      /** 结果照片回显操作 */
      findResult(row) {
          this.reset();
          this.open = true;
          const rrcid = row.rrcid;
          listCheckId(rrcid).then(response => {
              this.form.rrcresult = response.data[0].rrcresult;
              const rrcpicture=response.data[0].rrcpicture;
              showImage(rrcpicture).then(response => {
                  this.form.rrcpicture="data:image/jpeg;base64," + response;
                  console.log(response)
              });

          });
      },
  }
};
</script>
